#!/bin/env python
#!-*- coding:utf8 -*-

import requests
import json
import time
import os
from epics import caget

def create_record(value):
    data = []
    record = {}
    record['metric'] = 'epics:aiExample1'
    record['endpoint'] = os.uname()[1]
    record['timestamp'] = int(time.time())
    record['step'] = 30
    record['value'] = float(value)
    record['counterType'] = 'GAUGE'
    record['tags'] = 'id=epics'
    data.append(record)
    return data

def getPVValue(pvName):
    return caget(pvName)

data = create_record(getPVValue('csnsHost:aiExample1'))
if data:
    print json.dumps(data)
